<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var arr = [1, 5, 6, 3, 4, 9, 8, 3, 7]
        function maxMin(arr) {
            var max = arr[0]
            var max_index = 0
            var min = arr[arr.length - 1]
            var min_index = null
            for (var i = 1; i < arr.length; i++) {
                if (arr[i] > max) {
                    max = arr[i]
                    max_index = i
                } else if (arr[i] < min) {
                    min = arr[i]
                    min_index = i
                } else if (arr[i] == max || arr[i] == min) {
                    arr[i] == max ? max_index = max_index + '、'+ i : max_index
                    arr[i] == min ? min_index = min_index + '、'+ i : min_index
                }
            }
            console.log("最大的值是" + max + "\t符合要求的下标分别是" + max_index + "\n" +
                "最小的值是" + min + "\t符合要求的下标分别是" + min_index);
        }

        maxMin(arr)
    </script>
</head>

<body>

</body>

</html>